<?php
session_start();
if ($_SESSION['auth'] != true || ($_SESSION['rule'] != "PROVIDER" && $_SESSION['rule']!="PUBLISHER")) {
	die('Not log in');
}
include ('edit_item.php');
?>
<input type="button" name="save" value="Apply" id="editItem"/>
<input type="button" name="save" value="Remove" id="removeItem"/>
<script language="javascript" type="text/javascript">
$(document).ready (
	function () {
		$('#editItem').click(editItem);
		$('#removeItem').click(removeItem);			
	}
);
function editItem(){
	var err = itemReq();
	if(err != ''){
		$('#status').show('fast');
		$('#status').html(err);
		return;
	}
	$('#status').show(200);
	$('#status').text('Waiting server');
	var serialize = $('form').serialize();//$('form').serializeArray( );
	serialize = serialize.replace(/description/, "nothing");
	serialize += "&description="+escape(tinyMCE.getContent());
	$.post("provider_operation.php?action=edit_item",serialize, 
	  function(data){
		$('#status').text(data);
	  });

}

function removeItem(){
	var err = itemReq();
	if(err != ''){
		$('#status').show('fast');
		$('#status').html(err);
		return;
	}
	$('#status').show(200);
	$('#status').text('Waiting server');
	var serialize = $('form').serialize();//$('form').serializeArray( );
	serialize = serialize.replace(/description/, "nothing");
	serialize += "&description="+escape(tinyMCE.getContent());
	$.post("provider_operation.php?action=remove_item",serialize, 
	  function(data){
		window.location.href = 'about:blank';
	  });

}
</script>
